package leetcode101.mathematical_problem;

/**
 * @author Synhard
 * @version 1.0
 * @Class leetcode101.graph.Code1
 * @Description TODO
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-04-24 9:18
 */
public class Code1 {

    public static void main(String[] args) {
        System.out.println(gcb(78, 326));
        System.out.println(lcm(78, 326));
    }

    /*
    辗转相除法求两个数的最大公约数
     */
    public static int gcb(int a, int b) {
        int max = a - b > 0 ? a : b;
        int min = a + b - max;
        if (max % min == 0) {
            return min;
        }
        return gcb(min, max % min);
    }

    /*
    两个数相乘再除以这两个数的最小公倍数得到两个数的最小公倍数
     */
    public static int lcm(int a, int b) {
        return a * b / gcb(a, b);
    }
}
